package com.example.fitnessservice.module.dao.directormapper;

import com.example.fitnessservice.module.pojo.Coach;
import com.example.fitnessservice.module.pojo.CourseDetails;
import com.example.fitnessservice.module.pojo.CourseDetailsCamp;
import org.apache.ibatis.annotations.*;

import java.util.List;

//主管的mapper
@Mapper
public interface DirectorMapper {
    //查询主管对应的教练，以及相关教练的课程
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "directorId",column = "director_id"),
            @Result(property = "name",column = "name"),
            @Result(property = "age",column = "age"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "qq",column = "qq"),
            @Result(property = "sex",column = "sex"),
            @Result(property = "level",column = "level"),
            @Result(property = "email",column = "email"),
            @Result(property = "fans",column = "fans"),
            @Result(property = "balance",column = "balance"),
            @Result(property = "courseDetails",column = "id",many = @Many(select="com.example.fitnessservice.module.dao.classmapper.ClassMapper.findCourseByCoachId")),
            @Result(property = "camps", column = "id", many = @Many(select = "com.example.fitnessservice.module.dao.classmapper.ClassMapper.findCampByCoachId"))
    })
    @Select("select * from coach where director_id = #{directorId}")
    public List<Coach> findCoachByDirectorId(Integer directorId);

    /**
     * 添加课程表中的信息
     * @param courseDetails
     * @return
     */
    @Insert("insert into course_details values (null, #{courseName}, #{placeId}, #{courseCoachId}, 2, #{courseStartTime}, #{courseEndTime}, #{courseStatus}, #{courseDescription}, #{courseMoney}, 0)")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")   //将刚刚插入的数据的id返回
    public int addCourseByCoachId(CourseDetails courseDetails);

    /**
     * 删除课程信息
     * @param courseId
     * @return
     */
    @Delete("delete from course_details where id = #{courseId}")
    public int deleteCourseByCourseId(Integer courseId);

    /**
     * 添加教练课程关联表中的信息
     * @param courseChiefCoachId
     * @param id
     * @return
     */
    @Insert("insert into coach_course values (null, #{cid}, #{cuid})")
    public int addCoachCourse(@Param("cid") Integer courseChiefCoachId, @Param("cuid") Integer id);

    /**
     * 删除教练课程关联表中的信息
     * @param courseId
     * @return
     */
    @Delete("delete from coach_course where cuid = #{courseId}")
    public int deleteCoachCourse(Integer courseId);

    /**
     * 根据课程id查询课程课程信息
     * @param courseId
     * @return
     */
    @Select("select * from course_details where id = #{courseId}")
    public CourseDetails findCourseById(Integer courseId);

    /**
     * 如果课程表中课程对应的教练发生改变，更新教练课程表中的信息
     * @param cid
     * @param id
     * @return
     */
    @Update("update coach_course set cid = #{cid} where cuid = #{cuid}")
    public int updateCoachCourse(@Param("cid") Integer cid, @Param("cuid") Integer id);

    /**
     * 更新课程表中的信息
     * @param courseDetails
     * @return
     */
    @Update("update course_details set course_name = #{courseName}, place_id = #{placeId}, course_coach_id = #{courseCoachId}, course_type = #{courseType}, course_start_time = #{courseStartTime}, course_end_time = #{courseEndTime}, course_description = #{courseDescription}, course_money = #{courseMoney} where id = #{id}")
    public int updateCourseDetails(CourseDetails courseDetails);

    /**
     * 添加训练营,每次添加训练营的时候，训练营都是未开课的状态
     *
     * @param courseDetailsCamp
     * @return
     */
    @Insert("insert into course_details_camp values (null, #{courseName}, #{placeId}, #{courseCoachId}, #{courseStartTime}, #{courseEndTime}, 2, #{courseDescription}, #{courseMoney}, 0)")
    public int addCamp(CourseDetailsCamp courseDetailsCamp);

    /**
     * 删除训练营
     * @param campId
     * @return
     */
    @Delete("delete from course_details_camp where id = #{campId}")
    public int deleteCamp(Integer campId);

    /**
     * 修改训练营信息
     *
     * @param courseDetailsCamp
     * @return
     */
    @Update("update course_details_camp set course_name =#{courseName}, place_id = #{placeId}, course_coach_id = #{courseCoachId},  course_start_time = #{courseStartTime}, course_end_time = #{courseEndTime}, course_type = #{courseType}, course_description = #{courseDescription}, course_money = #{courseMoney}, where id = #{id}")
    public int updateCamp(CourseDetailsCamp courseDetailsCamp);

    /**
     * 查询训练营的课程编号的最大值
     *
     * @return
     */
    @Select("select Max(course_id)  from course_details_camp")
    public Integer findMaxCourseId();
}
